import socket
import _thread
import time
import  sys

def test(msg):
    ip_port = ('139.155.175.228', 9090)
    BUFSIZE = 1024
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect_ex(ip_port)  # 拨电话

    while True:  # 新增通信循环,客户端可以不断发收消息
        # msg = input('>>: ').strip()
        # if len(msg) == 0: continue
        time.sleep(0.5)
        print("发消息:"+msg)
        # s.send(msg.encode('utf-8'))  # 发消息,说话(只能发送字节类型)

        s.send("你好".encode('utf-8'))
        feedback = s.recv(BUFSIZE)  # 收消息,听话
        print(feedback.decode('utf-8'))


if __name__ == "__main__":

    try:
        for tt in range(1, 1000):
            time.sleep(0.09)
            _thread.start_new_thread(test, ("开始执行任务Thread-"+str(tt), ))
    except:
        print("Error: 无法启动线程")



    while 1:
        pass
    # test()
